
package ija.controller;

import ija.model.CheckersModel;
import ija.xls.notation.GameMove;
import ija.model.players.Player;
import ija.model.players.ComputerPlayer;
import java.util.ArrayList;
import java.util.List;
import ija.model.types.Color;
import ija.model.basis.Figure;

public class CheckersController implements GameController {
  protected GameStatus Status;
  protected CheckersModel Model;
  public enum GameStatus {
	  stateMenu, stateSettings, stateGame;
  }  
  
  public CheckersController() {
	this.Status = GameStatus.stateMenu;	
  }
  
  @Override
  public CheckersModel getModel() {	 
	return this.Model;
  }
  
  @Override
  public void ShowSettings() {
	this.Status = GameStatus.stateSettings;
  }
  
  @Override
  public void SaveSettings() {
	// save settings into xml
	this.Status = GameStatus.stateMenu;
  }
  
  @Override
  public void StartGame() {	 
	this.Status = GameStatus.stateGame;
	this.Model.initGame(Color.BLACK);
  }
  
  @Override
  public void SaveGame() {
	  
  }
  
  @Override
  public void EndGame() {
	this.Status = GameStatus.stateMenu;  
  }
  
  @Override
  public void ConnectWithPlayer(Player player) {
	  
  }
  
  @Override
  public void TurnRound() {
	    
  }
  
  @Override
  public GameMove PlayAI(Player player) {
	return ((ComputerPlayer)player).calculateMove();  
  }
  
  @Override
  public List<String> GetAllMoves (Color color) {
	boolean jumpsonly = false;
	List <String>MoveList = new ArrayList<>();
	for (Figure fig: Model.getDesk().getAllFigures(color)){
	  jumpsonly = fig.getMoves(MoveList, jumpsonly) || jumpsonly;
	} 
	return MoveList;
  }
  
  public boolean Verify (Color color, String moveNotation) {
	for (String movable: GetAllMoves(color)){
		if (movable == moveNotation)
			return true; 
	} 
	return false;
  }
}